
Component({
  /**
   * tabbar变化函数
   */
  pageLifetimes: {
    show() {
      if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 2
        })
      }
    }
  },
  data: {
    ecConfig: {}
  },
  

  methods: {

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
      this.initChart();
    },
    initChart: function () {
      this.echartsComponent = this.selectComponent('#myChart');
      this.echartsComponent.init((canvas, width, height) => {
        // 初始化图表
        const chart = echarts.init(canvas, null, {
          width: width,
          height: height
        });
        this.setChartOption(chart);
        return chart;
      });
    },
    setChartOption: function (chart) {
      var option = {
        title: {
          text: '示例图表'
        },
        tooltip: {},
        legend: {
          data: ['销量']
        },
        xAxis: {
          data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
        },
        yAxis: {},
        series: [{
          name: '销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        }]
      };
      chart.setOption(option);
    },
    
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady:function() {
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow:function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide:function() {

    },
 
  },
    
})
  


